from django.db import models


# Create your models here.

# 用户信息表
class UserInfo(models.Model):
    sex_choices = (
        (1, '男'),
        (2, '女'),
    )
    username = models.CharField(verbose_name='用户名', max_length=32)
    password = models.CharField(verbose_name='密码', max_length=32)
    sex = models.IntegerField(verbose_name='性别', choices=sex_choices, null=True, blank=True)
    age = models.PositiveSmallIntegerField(verbose_name='年龄', null=True, blank=True)


# 管理员信息表
class Admin(models.Model):
    sex_choices = (
        (1, '男'),
        (2, '女'),
    )
    manager_choices = (
        (1, '是'),
        (0, '否'),
    )
    admin_name = models.CharField(verbose_name='管理员名', max_length=32)
    password = models.CharField(verbose_name='密码', max_length=32)
    sex = models.IntegerField(verbose_name='性别', choices=sex_choices, null=True, blank=True)
    age = models.PositiveSmallIntegerField(verbose_name='年龄', null=True, blank=True)
    manager = models.IntegerField(verbose_name='总管理员', default=0, choices=manager_choices)


# 书籍信息表
class Books(models.Model):
    ISBN = models.CharField(verbose_name='ISBN', max_length=64)
    book_name = models.CharField(verbose_name='书名', max_length=32)
    author = models.CharField(verbose_name='作者', max_length=32)
    press = models.CharField(verbose_name='出版社', max_length=32)
    price = models.PositiveIntegerField(verbose_name='价格')
    num = models.PositiveSmallIntegerField(verbose_name='数量', default=10)


# 借书记录表
class Records(models.Model):
    status_choices = (
        (1, '已归还'),
        (0, '未归还'),
    )
    flag_choices = (
        (2, '未归还'),
        (1, '超时归还'),
        (0, '按时归还'),
    )
    userId = models.ForeignKey(verbose_name='借书者编号', to='UserInfo', on_delete=models.CASCADE)
    bookId = models.ForeignKey(verbose_name='书籍编号', to='Books', on_delete=models.CASCADE)
    borrowing_time = models.DateTimeField(verbose_name='借书时间', auto_now_add=True)
    due_date = models.DateTimeField(verbose_name='应还日期')
    return_time = models.DateTimeField(verbose_name='归还日期', null=True, blank=True)
    status = models.IntegerField(verbose_name='归还状态', choices=status_choices, default=0)
    flag = models.IntegerField(verbose_name='是否超时', choices=flag_choices, default=2)
